package edu.uclmgmu.bacteriosec.aspects.sis;

import java.io.InputStream;

import edu.uclmgmu.bacteriosec.aspects.common.Store;

privileged aspect SIS_CountCalls {
	private InputStream input;

	java.io.InputStream around(java.net.Socket f) : target(f) && call(java.io.InputStream java.net.Socket.getInputStream()) {
		InputStream auxi=proceed(f);
		if (auxi.getClass().getName().equals("java.net.SocketInputStream")) {
			this.input=auxi;
			System.out.println("Capturado el SocketInputStream");
		}
		return proceed(f);
	}

	after(java.io.InputStream f, byte[] b, int off, int len) : target(f) && args(b, off, len) && call(int InputStream.read(byte[], int, int)) {
		if (this.input!=null) {
			int counter=Store.get(thisJoinPointStaticPart.getSignature());
			Store.updateNumberOfCalls(thisJoinPointStaticPart.getSignature(), counter++);
			Store.put(thisJoinPointStaticPart.getSignature(), counter);
		}
	}
}
